﻿@inject IHttpService _httpService
@inject IDataCacheService _dataCacheService

<CnGalWebSite.Components.Containers.MasaTitleContainer Outline Title="@Title" Icon="@TitleIcon" Class="mb-4">
    <ButtonContent>

        <MButton Rounded Color="primary"  OnClick="GetNewRandomList">
            <MIcon Left>mdi-refresh </MIcon>
            换一组
        </MButton>


    </ButtonContent>
    <ChildContent>
        <div class="row">
            @foreach (var item in Model)
            {
                <div class="@(IsTransverse?"col-12 col-lg-6 mb-4":"col-12 mb-4" )">
                    <NormalPerfectionInforTipView Model="@item"></NormalPerfectionInforTipView>
                </div>
            }
        </div>
    </ChildContent>

</CnGalWebSite.Components.Containers.MasaTitleContainer>
@code {

    public List<PerfectionInforTipViewModel> Model { get; set; } = new List<PerfectionInforTipViewModel>();

    [Parameter]
    public string Title { get; set; }
    [Parameter]
    public string TitleIcon { get; set; }
    [Parameter]
    public PerfectionLevel Level { get; set; }
    [Parameter]
    public bool IsTransverse { get; set; }
    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }

    protected override async Task OnInitializedAsync()
    {
        try
        {
            Model = await _httpService.GetAsync<List<PerfectionInforTipViewModel>>("api/perfections/GetPerfectionLevelRadomList/" + (int)Level);
        }
        catch (Exception ex)
        {
            await ErrorHandler.ProcessError(ex, "获取随机词条完善度列表失败");
        }
    }


    public async Task GetNewRandomList()
    {
        await OnInitializedAsync();
    }



}
